<?php
/**
 *
 * Voorbeeld implementatie van de User Control interface.
 * @author Ferry Guikema
 *
 */
@session_start();
require_once('iUserControl.php');

class UserRights implements iUserControl {

	private $folders = Array();
	
	/*** constructor, maak een array van gebruikers en rechten ***/
	function __construct()
	{
		/*$this->folders = Array(''  => Array('ferry' => Array( 'read'			=> 1,
								       'write'  		=> 0,
								       'delete' 		=> 0),
						     'herman' => Array('read'   		=> 1,
								       'write'  		=> 0,
								       'delete' 		=> 0)
						     ),
				       '/ferry'  => Array('ferry' => Array('read'   		=> 1,
									   'write'   		=> 1,
									   'delete'  		=> 1),
							 'herman' => Array('read'   		=> 0,
									   'write'  		=> 0,
									   'delete' 		=> 0)
							 ),
				       '/herman' => Array('ferry' => Array('read'   		=> 0,
									   'write'  		=> 0,
									   'delete' 		=> 0),
							 'herman' => Array('read'   		=> 1,
									   'write'  		=> 1,
									   'delete' 		=> 1)
							 ),
				       '/public' => Array('ferry' => Array('read'   		=> 1,
									   'write'  		=> 1,
									   'delete' 		=> 1),
							 'herman' => Array('read'   		=> 1,
									   'write'  		=> 1,
									   'delete' 		=> 1)
							 )
				      );
		file_put_contents('/opt/lampp/htdocs/webfy/userrights.txt', serialize($this->folders)); // */
		$this->folders = unserialize( file_get_contents ('/opt/lampp/htdocs/webfy/userrights.txt') ); 

	} # ctor
	
	/*** controleer gebruikersrechten ***/
	public function hasRights($folder, $action)
	{
		//echo 'folder: ' . $folder;
		if ( array_key_exists($folder, $this->folders) )
		{
			if ( array_key_exists( $_SESSION['user'], $this->folders[$folder] ) )
			{
				return $this->folders[$folder][$_SESSION['user']][$action];
			}
		}
		return 0;
	} # func hasRights

	public function addRights($folder)
	{
		$this->folders[$folder] = Array($_SESSION['user'] => Array('read' => 1,
									   'write' => 1,
									   'delete' => 1) );
		file_put_contents('/opt/lampp/htdocs/webfy/userrights.txt', serialize($this->folders));
	}
}
?>
